package com.it;

import com.it.pojo.Event;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * @author code1997
 */
public class EventSourceTest {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
        executionEnvironment.setParallelism(1);
        //1.从文件中读取数据
        DataStreamSource<String> textSource = executionEnvironment.readTextFile("data/chapter01/click.txt");
        textSource.print();
        //2.从集合中读取数据
        List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
        DataStreamSource<Integer> intsSource = executionEnvironment.fromCollection(ints);
        intsSource.print();

        List<Event> events = Arrays.asList(new Event("tom", "index", 2000L), new Event("kangkang", "index", 2000L), new Event("flow", "index", 2000L));
        DataStreamSource<Event> eventDataStreamSource = executionEnvironment.fromCollection(events);
        eventDataStreamSource.print();

        //从元素中:可以用来代替集合的形式.
        DataStreamSource<Event> eventDataStreamSource2 = executionEnvironment.fromElements(new Event("tom", "index", 2000L), new Event("kangkang", "index", 2000L), new Event("flow", "index", 2000L));
        eventDataStreamSource2.print();


        executionEnvironment.execute();
    }
}
